package MYBatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

public class SubjectDaoTest {
    public static void main(String[] args) {
        try {
            InputStream in = Resources.getResourceAsStream("MYBatis\\mybatis-config.xml");
            SqlSessionFactory build = new SqlSessionFactoryBuilder().build(in);
            SqlSession sqlSession = build.openSession();
            //>>>Connection connection = sqlSession.getConnection();
            SubjectDao mapper = sqlSession.getMapper(SubjectDao.class);
            System.out.println(mapper.getClass().getName());
            System.out.println(Arrays.toString(mapper.getClass().getInterfaces()));
            System.out.println("总共有"+mapper.count()+"课程");
            System.out.println(mapper.map(3));
            System.out.println(mapper.map1());
//            删除
            mapper.del("62,58");
            mapper.insert(new Subject("xiaokong",30,7));
            mapper.update(new Subject(57,"xiaozuo",35,7));
            //分页
            HashMap<String,Object> map = new HashMap<>();
            map.put("startIndex",0);
            map.put("pageSize",6);
            List<Subject> a=mapper.limit(map);
            a.forEach(System.out::println);

//            List<Subject> a=mapper.like("java");
//            a.forEach(System.out::println);

//            List<Subject> all = mapper.findALL();
//            all.forEach(System.out::println);

//            List<Subject> b=mapper.del(62);
//            b.forEach(System.out::println);
//            sqlSession.commit();
            sqlSession.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
